// 接口地址：http://cba.itlike.com/public/index.php?s=/api/page/detail
// 请求方式：get

// // swiper初始化代码（思考：在Vue中应该在哪里初始化）
// const mySwiper = new Swiper(".swiper", {
//   speed: 1000,
//   loop: true,
//   autoplay: {
//     disableOnInteraction: false,
//     delay: 2000,
//   },
//   pagination: {
//     el: ".swiper-pagination",
//   },
//   centeredSlides: true,
//   observer: true, //修改swiper自己或子元素时，自动初始化swiper
//   observeParents: true, //修改swiper的父元素时，自动初始化swiper
//   observerUpdate: true,
// });


const app = new Vue({
  el: '#app',
  data: {
    swiperList: JSON.parse(localStorage.getItem('swiperList')) || [], // 轮播数据
    navList: JSON.parse(localStorage.getItem('navList')) || [], // 导航数据
    goodsList: JSON.parse(localStorage.getItem('goodsList')) || [] // 商品数据
  },
  async created () {
    const res = await axios({
      url: 'http://cba.itlike.com/public/index.php?s=/api/page/detail'
    })
    console.log(res.data.data.pageData)
    const res1 = res.data.data.pageData
    localStorage.setItem('swiperList', JSON.stringify(res1.items[1].data))
    localStorage.setItem('navList', JSON.stringify(res1.items[3].data))
    localStorage.setItem('goodsList', JSON.stringify(res1.items[6].data))

  },
  mounted () {
    const mySwiper = new Swiper(".swiper", {
      speed: 1000,
      loop: true,
      autoplay: {
        disableOnInteraction: false,
        delay: 2000,
      },
      pagination: {
        el: ".swiper-pagination",
      },
      centeredSlides: true,
      observer: true, //修改swiper自己或子元素时，自动初始化swiper
      observeParents: true, //修改swiper的父元素时，自动初始化swiper
      observerUpdate: true,
    });
  }
})